var util = require('util'),
	EventEmitter = require('events').EventEmitter;

//-------------------------------------------------------------------
function MyStream() { //新建一个类
}
util.inherits(MyStream, EventEmitter); //使这个类继承EventEmitter


// basic usage
// create an obj of the class, receive and emit event
var stream = new MyStream();
stream.on('haha',function(){console.log('haha')});
stream.emit('haha');


// advanced: prototype
MyStream.prototype.write = function(data) { //定义一个新方法
	this.emit("data", data); //在此触发名为"data"事件
}
stream.on("data", function(data) { //注册监听器，监听名为"data"事件
	console.log('Received data: "' + data + '"');
})
stream.write("It works!"); // Received data: "It works!"